package com.eascs.web.o2o.report.service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.app.runtime.RuntimeSetting;
import com.eascs.common.util.DigestUtils;
import com.eascs.common.util.UuidUtil;
import com.eascs.notify.sms.SmsNotifier;
import com.eascs.notify.sms.SmsNotifyRequest;
import com.eascs.notify.sms.SmsNotifyResponse;
import com.eascs.web.o2o.dc.dao.ServiceDao;
import com.eascs.web.o2o.report.constants.FefundConstants;
import com.eascs.web.o2o.report.dao.BaseReportDao;
import com.eascs.web.o2o.report.dao.FefundDao;
import com.eascs.web.o2o.report.dao.O2OMessageDao;
import com.eascs.web.o2o.report.entity.HrEmployee;
import com.eascs.web.o2o.report.entity.O2OMessage;
import com.eascs.web.o2o.report.entity.TransferO2OMessage;
import com.eascs.web.o2o.report.util.DateUtil;
import com.eascs.workflow.common.entity.sys.SysMessage;

@Service
public class FefundService {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	FefundDao fefundDao;
	@Autowired
	BaseReportDao baseReportDao;
	@Autowired
	O2OMessageDao o2OMessageDao;
	@Reference
	private SmsNotifier smsNotifier;
	@Autowired
	private ServiceDao serviceDao;

	// // private String env = RuntimeSetting.get().getEnv();
	// // RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// // 放款日发送(每十分钟执行一次)
	// public void findFundFKS() {
	// RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// int index = 0;// 第几页
	// int total = 0;// 第几条数据
	//
	// logger.info("老系统放款日当天发送短信数据插入开始==============");
	// logger.info("老系统放款日当天发送短信所属环境是：" + runtimeSetting.getEnv() +
	// "===============================================");
	// // 第一步查出orcle中符合发送条件的数据
	// String sql = "select lr.mobile,
	// lr.loanername,rd.refundno,rd.loadapplycode from eadb.O2O_REFUND rd " + "
	// left join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno" + "
	// where rd.bankrefundcode = 'GACZ' and rd.billstatus = 'RUN' and
	// rd.issendmsg = 'N'";
	//
	// while (index >= 0) {
	// SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
	// FefundConstants.DATA_LIMIT, index, sql);
	// // oracle查询
	// PageResult<Object[]> pageResult =
	// fefundDao.findDataWithPage(sqlPageQuery);
	// for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
	// Object[] obj = pageResult.getData().get(i);
	// logger.debug("total:{},{}", ++total, obj.toString());
	// String content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.FKS_CONTEXT;
	// O2OMessage message = new O2OMessage();
	// message.setContent(content);
	//
	// if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
	// message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
	// } else {
	// message.setReceiveTelphone("13425116953");// obj[0].toString()
	// }
	// message.setReceiveName(obj[1].toString());
	// message.setSendName(FefundConstants.SENDNAME);
	// message.setCreateTime(new Date());
	// message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
	// message.setMessageType(O2OMessage.MESSAGE_TYPE_FK);
	// message.setPlatformType(O2OMessage.PLATFORM_TYPE_OLD);
	// message.setRelevanceId(obj[2].toString());
	// message.setLoanapplyno(obj[3].toString());
	//
	// try {
	// // 循环插入 workflow 里面的表中
	// // workflowDao.saveEntity(message);
	// // sysSendEmailOrMessageService.insertMessage(message);
	// // workflowDao.excuteSql("insert into wf_message
	// //
	// (content,receive_name,receive_telphone,send_name,send_type,status,create_time)
	// // values(?,?,?,?,?,?,?) ",obj[0]);
	// // 判断本地表是否有这条数据
	// boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_FK,
	// obj[2].toString());
	// if (!flag) {
	// o2OMessageDao.saveEntity(message);
	// }
	// } catch (DataIntegrityViolationException e) {
	// logger.error("主键重复", e);
	// }
	// // 更新eaoa表中的数据
	// String updatesql = "update eadb.O2O_REFUND set issendmsg = 'Y' where
	// refundno = ?";
	// int result = fefundDao.excuteSql(updatesql, obj[2].toString());
	// if (result > 0) {
	// logger.info(obj[2].toString() +
	// "====eaoa中O2O_REFUND表状态修改成功==============");
	// } else {
	// logger.info(obj[2].toString() +
	// "====eaoa中O2O_REFUND表状态修改失败==============");
	// }
	// }
	//
	// if (pageResult.getPageTotal() > index) {
	// index++;
	// } else {
	// index = -1;
	// }
	// }
	// logger.info("放款日当天发送短信数据插入成功==============");
	// }

	// // 还息日前两天发送(每天执行一次)
	// public void findFundBeforeOneDay() {
	// RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// int index = 0;// 第几页
	// int total = 0;// 第几条数据
	// logger.info("老系统还息日前两天发送发送短信数据插入开始==============");
	// logger.info("老系统还息日前两天发送短信所属环境是：" + runtimeSetting.getEnv() +
	// "===============================================");
	// // 第一步查出orcle中符合发送条件的数据
	// String sql = "select lr.mobile,
	// lr.loanername,rl.refundlineno,rd.loadapplycode from eadb.O2O_REFUNDLINE
	// rl left join eadb.O2O_REFUND rd on rd.refundno = rl.refundno " + " left
	// join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno "
	// + " where to_char(sysdate + 2, 'yyyy-MM-dd') = to_char(rl.interestdate,
	// 'yyyy-MM-dd') and rd.billstatus = 'RUN' and rd.bankrefundcode = 'GACZ'
	// and rl.principalremained != 0 ";
	// while (index >= 0) {
	// SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
	// FefundConstants.DATA_LIMIT, index, sql);
	// // oracle查询
	// PageResult<Object[]> pageResult =
	// fefundDao.findDataWithPage(sqlPageQuery);
	// for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
	// Object[] obj = pageResult.getData().get(i);
	// logger.info("total:{},{}", ++total, obj.toString());
	// String content=null;
	// if(isBillCode(obj[3].toString())){
	// content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-2) + "还息，" +
	// FefundConstants.PAY_MENT_CONTEXT1;
	// }else{
	// content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-2) + "还息，" +
	// FefundConstants.BEFORE_CONTEXT;
	// }
	// O2OMessage message = new O2OMessage();
	// message.setContent(content);
	// if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
	// message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
	// } else {
	// message.setReceiveTelphone("13425116953");// obj[0].toString()
	// }
	// message.setReceiveName(obj[1].toString());
	// message.setSendName(FefundConstants.SENDNAME);
	// message.setCreateTime(new Date());
	// message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
	// message.setMessageType(O2OMessage.MESSAGE_TYPE_FX2);
	// message.setPlatformType(O2OMessage.PLATFORM_TYPE_OLD);
	// message.setRelevanceId(obj[2].toString());
	// message.setLoanapplyno(obj[3].toString());
	// try {
	// // 判断本地表是否有这条数据
	// boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_FX2,
	// obj[2].toString());
	// if (!flag) {
	//
	// o2OMessageDao.saveEntity(message);
	// }
	// } catch (DataIntegrityViolationException e) {
	// logger.error("主键重复", e);
	// }
	// }
	//
	// if (pageResult.getPageTotal() > index) {
	// index++;
	// } else {
	// index = -1;
	// }
	// }
	// logger.info("还息日前两天发送发送短信数据插入成功==============");
	// }

	// // 贷款到期前15天发送(每天执行一次)
	// public void findFundBeforeEnd15() {
	// RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// int index = 0;// 第几页
	// int total = 0;// 第几条数据
	// logger.info("老系统贷款到期前15天发送短信数据插入开始==============");
	// logger.info("老系统贷款到期前15天发送短信所属环境是：" + runtimeSetting.getEnv() +
	// "===============================================");
	// // 第一步查出orcle中符合发送条件的数据
	// String sql = "select lr.mobile,
	// lr.loanername,rl.refundlineno,rd.loadapplycode from eadb.O2O_REFUNDLINE
	// rl left join eadb.O2O_REFUND rd on rd.refundno = rl.refundno " + " left
	// join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno "
	// + " where to_char(sysdate + 15, 'yyyy-MM-dd') = to_char(rl.interestdate,
	// 'yyyy-MM-dd') and rd.billstatus = 'RUN' and rl.principalremained = 0 and
	// rd.bankrefundcode = 'GACZ' ";
	//
	// while (index >= 0) {
	// SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
	// FefundConstants.DATA_LIMIT, index, sql);
	// // oracle查询
	// PageResult<Object[]> pageResult =
	// fefundDao.findDataWithPage(sqlPageQuery);
	// for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
	// Object[] obj = pageResult.getData().get(i);
	// logger.info("total:{},{}", ++total, obj.toString());
	// String content=null;
	// if(isBillCode(obj[3].toString())){
	// content =FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-15) + "归还本息，" +
	// FefundConstants.BEFOREEND15_CONTEXT;
	// }else{
	// content =FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-15) + "归还本息，" +
	// FefundConstants.BEFOREEND15_CONTEXT;
	// }
	// O2OMessage message = new O2OMessage();
	// message.setContent(content);
	// if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
	// message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
	// } else {
	// message.setReceiveTelphone("13425116953");// obj[0].toString()
	// }
	// message.setReceiveName(obj[1].toString());
	// message.setSendName(FefundConstants.SENDNAME);
	// message.setCreateTime(new Date());
	// message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
	// message.setMessageType(O2OMessage.MESSAGE_TYPE_DK15);
	// message.setPlatformType(O2OMessage.PLATFORM_TYPE_OLD);
	// message.setRelevanceId(obj[2].toString());
	// message.setLoanapplyno(obj[3].toString());
	// try {
	// // 判断本地表是否有这条数据
	// boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_DK15,
	// obj[2].toString());
	// if (!flag) {
	// o2OMessageDao.saveEntity(message);
	// }
	// } catch (DataIntegrityViolationException e) {
	// logger.error("主键重复", e);
	// }
	// }
	//
	// if (pageResult.getPageTotal() > index) {
	// index++;
	// } else {
	// index = -1;
	// }
	// }
	// logger.info("贷款到期前15天发送发送短信数据插入成功==============");
	// }

	// // 贷款到期前两天发送(每天执行一次)
	// public void findFundBeforeEnd() {
	// RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// int index = 0;// 第几页
	// int total = 0;// 第几条数据
	// logger.info("老系统贷款到期前两天发送短信数据插入开始==============");
	// logger.info("老系统贷款到期前两天发送短信所属环境是：" + runtimeSetting.getEnv() +
	// "===============================================");
	// // 第一步查出orcle中符合发送条件的数据
	// String sql = "select lr.mobile,
	// lr.loanername,rl.refundlineno,rd.loadapplycode from eadb.O2O_REFUNDLINE
	// rl left join eadb.O2O_REFUND rd on rd.refundno = rl.refundno " + " left
	// join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno "
	// + " where to_char(sysdate + 2, 'yyyy-MM-dd') = to_char(rl.interestdate,
	// 'yyyy-MM-dd') and rd.billstatus = 'RUN' and rl.principalremained = 0 and
	// rd.bankrefundcode = 'GACZ' ";
	//
	// while (index >= 0) {
	// SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
	// FefundConstants.DATA_LIMIT, index, sql);
	// // oracle查询
	// PageResult<Object[]> pageResult =
	// fefundDao.findDataWithPage(sqlPageQuery);
	// for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
	// Object[] obj = pageResult.getData().get(i);
	// logger.info("total:{},{}", ++total, obj.toString());
	// String content=null;
	// if(isBillCode(obj[3].toString())){
	// content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-2) + "归还本息，" +
	// FefundConstants.PAY_MENT_CONTEXT2;
	// }else{
	// content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-2) + "归还本息，" +
	// FefundConstants.BEFORE_CONTEXT2;
	// }
	// O2OMessage message = new O2OMessage();
	// message.setContent(content);
	// if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
	// message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
	// } else {
	// message.setReceiveTelphone("13425116953");// obj[0].toString()
	// }
	// message.setReceiveName(obj[1].toString());
	// message.setSendName(FefundConstants.SENDNAME);
	// message.setCreateTime(new Date());
	// message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
	// message.setMessageType(O2OMessage.MESSAGE_TYPE_DK2);
	// message.setPlatformType(O2OMessage.PLATFORM_TYPE_OLD);
	// message.setRelevanceId(obj[2].toString());
	// message.setLoanapplyno(obj[3].toString());
	// try {
	// // 判断本地表是否有这条数据
	// boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_DK2,
	// obj[2].toString());
	// if (!flag) {
	// o2OMessageDao.saveEntity(message);
	// }
	// } catch (DataIntegrityViolationException e) {
	// logger.error("主键重复", e);
	// }
	// }
	// if (pageResult.getPageTotal() > index) {
	// index++;
	// } else {
	// index = -1;
	// }
	// }
	// logger.info("贷款到期前两天发送短信数据插入成功==============");
	// }
	//
	// // 贷款到期前15天发送(每天执行一次)
	// public void findNewFundBeforeEnd15() {
	// RuntimeSetting runtimeSetting = RuntimeSetting.get();
	// int index = 0;// 第几页
	// int total = 0;// 第几条数据
	// logger.info("新系统贷款到期前15天发送短信数据插入开始==============");
	// logger.info("新系统贷款到期前15天短信所属环境是：" + runtimeSetting.getEnv() +
	// "===============================================");
	// // 第一步查出orcle中符合发送条件的数据
	// String sql = " select
	// lu.user_phone,lu.user_surname,ops.payments_id,l.bill_code from
	// o2o_payments_plan ops" + " LEFT JOIN o2o_loanapply l on l.bill_code =
	// ops.bill_code " + " LEFT JOIN o2o_loan_user lu on l.loan_id = lu.loan_id
	// "
	// + " where (l.data_source IS NULL OR l.data_source <> '2') and
	// residual_principal = 0 and payments_date = adddate(curdate(), '15 days')
	// and l.bank_loan_name = 'GACZ' ";
	//
	// while (index >= 0) {
	// SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
	// FefundConstants.DATA_LIMIT, index, sql);
	// // oracle查询
	// PageResult<Object[]> pageResult =
	// o2OMessageDao.findDataWithPage(sqlPageQuery);
	// for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
	// Object[] obj = pageResult.getData().get(i);
	// logger.debug("total:{},{}", ++total, obj.toString());
	// String content = FefundConstants.START_CONTEXT + obj[1] +
	// FefundConstants.MIDDLE_CONTEXT + "应于" +
	// DateUtil.getSpecifiedDayBefore(-15) + "归还本息，" +
	// FefundConstants.BEFOREEND15_CONTEXT;
	// O2OMessage message = new O2OMessage();
	// message.setContent(content);
	// if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
	// message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
	// } else {
	// message.setReceiveTelphone("13425116953");// obj[0].toString()
	// }
	// message.setReceiveName(obj[1].toString());
	// message.setSendName(FefundConstants.SENDNAME);
	// message.setCreateTime(new Date());
	// message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
	// message.setMessageType(O2OMessage.MESSAGE_TYPE_DK15);
	// message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
	// message.setRelevanceId(obj[2].toString());
	// message.setLoanapplyno(obj[3].toString());
	// try {
	// // 判断本地表是否有这条数据
	// boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_DK15,
	// obj[2].toString());
	// if (!flag) {
	// o2OMessageDao.saveEntity(message);
	// }
	// } catch (DataIntegrityViolationException e) {
	// logger.error("主键重复", e);
	// }
	// }
	//
	// if (pageResult.getPageTotal() > index) {
	// index++;
	// } else {
	// index = -1;
	// }
	// }
	// logger.info("贷款到期前15天发送发送短信数据插入成功==============");
	// }

	// 逾期短信发送查询service表
	public void findGACZOverdue() {
		int total = 0;
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		logger.info("查询系统逾期开始,所属环境是：[{}]", runtimeSetting.getEnv());
		String sql = "SELECT O.USER_PHONE,T.LOANERNAME,T.EAID,F.BILL_CODE FROM O2O_OVERDUE_REPORT T "
				+ " LEFT JOIN O2O_LOANAPPLY F ON T.BILLCODE=F.BILL_CODE "
				+ " LEFT JOIN O2O_LOAN_USER O ON O.LOANAPPLY_NO=F.LOANAPPLY_NO AND O.LOAN_ID=F.LOAN_ID "
				+ " AND  O.SPOUSE_ID IS NULL AND O.SPONSOR_TYPE IS NULL "
				+ " WHERE T.STATUS IN('1','2') AND T.BANKREFUNDCODE='GACZ' " + " AND T.ISNEW='Y' AND T.ISDEL='N' ";
		List<Object[]> pageResult = serviceDao.findObjectsList(sql);
		Integer count = pageResult.size();
		for (int i = 0; i < count; i++) {
			Object[] obj = pageResult.get(i);
			String content = FefundConstants.START_CONTEXT + obj[1] + FefundConstants.OVERDUE_CONTEXT;
			O2OMessage message = new O2OMessage();
			message.setContent(content);
			if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
				message.setReceiveTelphone(obj[0].toString());
			} else {
				message.setReceiveTelphone("13425116953");
			}
			message.setReceiveName(obj[1].toString());
			message.setSendName(FefundConstants.SENDNAME);
			message.setCreateTime(new Date());
			message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
			message.setMessageType(O2OMessage.MESSAGE_TYPE_YQ2);
			message.setLoanapplyno(obj[3].toString());
			message.setRelevanceId(obj[2].toString());
			message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
			try {
				boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_YQ2, obj[2].toString());
				if (!flag) {
					o2OMessageDao.saveEntity(message);
					total++;
				}
			} catch (DataIntegrityViolationException e) {
				logger.error("主键重复异常：[{}]", e);
			}
		}
		logger.info("查询逾期列表结束,发送短信数据插入成功条数：[{}]", total);
	}
	
	
	
	
		/**
		 * @Title: findNotGACZOverdue
		 * @Description: 非国安村镇银行逾期的第二天发送
		 * @author 张庆奇
		 * @return void
		 * @throws
		 * @date 2018年1月5日 下午2:30:50
		 */
		public void findNotGACZOverdue() {
			int total = 0;
			RuntimeSetting runtimeSetting = RuntimeSetting.get();
			logger.info("查询系统逾期开始,所属环境是：[{}]", runtimeSetting.getEnv());
			String sql = "SELECT O.USER_PHONE,T.LOANERNAME,T.EAID,F.BILL_CODE FROM O2O_OVERDUE_REPORT T "
					+ " LEFT JOIN O2O_LOANAPPLY F ON T.BILLCODE=F.BILL_CODE "
					+ " LEFT JOIN O2O_LOAN_USER O ON O.LOANAPPLY_NO=F.LOANAPPLY_NO AND O.LOAN_ID=F.LOAN_ID "
					+ " AND  O.SPOUSE_ID IS NULL AND O.SPONSOR_TYPE IS NULL "
					+ " WHERE T.STATUS IN('1','2') AND T.BANKREFUNDCODE not in('GACZ','EA') " + " AND T.ISNEW='Y' AND T.ISDEL='N' ";
			List<Object[]> pageResult = serviceDao.findObjectsList(sql);
			Integer count = pageResult.size();
			for (int i = 0; i < count; i++) {
				Object[] obj = pageResult.get(i);
				String content = FefundConstants.START_CONTEXT + obj[1] + FefundConstants.OVERDUE_CONTEXT;
				O2OMessage message = new O2OMessage();
				message.setContent(content);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					message.setReceiveTelphone(obj[0].toString());
				} else {
					message.setReceiveTelphone("13425116953");
				}
				message.setReceiveName(obj[1].toString());
				message.setSendName(FefundConstants.SENDNAME);
				message.setCreateTime(new Date());
				message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				message.setMessageType(O2OMessage.MESSAGE_TYPE_YQ2);
				message.setLoanapplyno(obj[3].toString());
				message.setRelevanceId(obj[2].toString());
				message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				try {
					boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_YQ2, obj[2].toString());
					if (!flag) {
						o2OMessageDao.saveEntity(message);
						total++;
					}
				} catch (DataIntegrityViolationException e) {
					logger.error("主键重复异常：[{}]", e);
				}
			}
			logger.info("查询逾期列表结束,发送短信数据插入成功条数：[{}]", total);
		}

	/**
	 * 查询service库中未发送的短信,插入到workflow库中发送。
	 */
	public void localToWorkflow() {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		logger.info("向workflow中插入短信数据（5分钟一次）开始,所属环境是：[{}]" + runtimeSetting.getEnv());
		int total = 0;
		String sql = "select * from o2o_message l where l.status = 0 ";
		List<O2OMessage> pageResult = serviceDao.findEntitys(sql, O2OMessage.class);
		Integer count = pageResult.size();
		for (int i = 0; i < count; i++) {
			O2OMessage o2oMessage = new O2OMessage();
			logger.debug("total:{},{}", o2oMessage.toString());
			o2oMessage = (O2OMessage) pageResult.get(i);
			SmsNotifyRequest smsCustomerRequest = new SmsNotifyRequest();
			smsCustomerRequest = TransferO2OMessage.transferSms(o2oMessage, smsCustomerRequest);
			try {
				com.eascs.notify.constant.ModelResult<SmsNotifyResponse> response = smsNotifier
						.notify(smsCustomerRequest);
				if (!response.isSuccess()) {
					logger.info("贷款编号：[{}],发送客户短信发送失败原因:{}", o2oMessage.getLoanapplyno(), response.getErrMsg());
				} else {
					o2OMessageDao.updateRelevanceId(null, o2oMessage.getMessageId(), O2OMessage.MESSAGE_STATUS_1);
					total++;
				}
			} catch (DataIntegrityViolationException e) {
				logger.error("主键重复异常:[{}]", e);
			}
		}
		logger.info("向workflow中插入短信数据（5分钟一次）成功,插入总条数：[{}]", total);
	}

	// 放款日发送
	public void findNewFundFKS() {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		int index = 0;
		int total = 0;
		logger.info("查询系统当日放款发送开始,所属环境是：[{}]", runtimeSetting.getEnv());
		String sql = "SELECT lu.user_phone,lu.user_surname,l.loanapply_no,l.bill_code,d.loan_bank from o2o_loanapply l "
				+ "	LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id and l.loanapply_no=lu.loanapply_no "
				+ "	and lu.spouse_id is null and lu.sponsor_type is null LEFT JOIN o2o_bank_loan_data d ON l.bill_code=d.bill_code AND d.is_del='N' "
				+ "	where l.wf_type = 'O' and d.loan_bank = 'GACZ'";
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index,
					sql);
			PageResult<Object[]> pageResult = o2OMessageDao.findDataWithPage(sqlPageQuery);
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);
				String content = FefundConstants.BEGIN_CONTEXT + obj[1] + FefundConstants.BEGIN_CONTEXT_END
						+ FefundConstants.FKS_CONTEXT;
				O2OMessage message = new O2OMessage();
				message.setContent(content);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
				} else {
					message.setReceiveTelphone("13425116953");// obj[0].toString()
				}
				message.setReceiveName(obj[1].toString());
				message.setSendName(FefundConstants.SENDNAME);
				message.setCreateTime(new Date());
				message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				message.setMessageType(O2OMessage.MESSAGE_TYPE_FK);
				message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				message.setRelevanceId(obj[2].toString());
				message.setLoanapplyno(obj[3].toString());
				try {
					boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_FK, obj[2].toString());
					if (!flag) {
						o2OMessageDao.saveEntity(message);
					}
				} catch (DataIntegrityViolationException e) {
					logger.error("主键重复:[{}]", e);
				}
			}

			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
		logger.info("查询系统当日放款发送结束,插入总记录:[{}]", total);
	}

	// 国安村镇银行还息日前n天发送(每天执行一次)
	public void GACZFundBeforeDay(int n) {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		int index = 0;// 第几页
		int total = 0;
		logger.info("查询国安村镇银行还息日前" + n + "两天开始,所属环境是：[{}]", runtimeSetting.getEnv());
		String sql = "select lu.user_phone,lu.user_surname,ops.payments_id,l.bill_code,ops.pay_total from "
		
				+ " ( SELECT nn.* from (select max(n.periods) as maxlength,n.bill_code  from o2o_payments_plan n where n.is_del='N' group by n.bill_code ) t,o2o_payments_plan nn where t.maxlength!=nn.periods and t.bill_code=nn.bill_code  and nn.is_del='N' ) "
				+ " ops "
				+ " LEFT JOIN o2o_loanapply l on l.bill_code = ops.bill_code  LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id "
				+ "	and l.loanapply_no=lu.loanapply_no  and lu.spouse_id is null and lu.sponsor_type is null "
				+ "	LEFT JOIN o2o_bank_loan_data d ON l.bill_code=d.bill_code AND d.is_del='N' "
				+ "	where  residual_principal != 0   and payments_date = adddate(curdate(),'" + n
				+ "  days') AND ops.is_del='N' " + "	and d.loan_bank = 'GACZ' ";
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index,
					sql);
			PageResult<Object[]> pageResult = o2OMessageDao.findDataWithPage(sqlPageQuery);
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);
				String content = null;
				if (isBillCode(obj[3].toString())) {
					content = FefundConstants.BEGIN_CONTEXT + obj[1] + FefundConstants.BEGIN_CONTEXT_END
							+ FefundConstants.MSG_MIDDLE_CONTEXT + DateUtil.getSpecifiedDayBefore(-n) + "归还" + obj[4]
							+ FefundConstants.PAY_MENT_CONTEXT1;
				} else {
					content = FefundConstants.BEGIN_CONTEXT + obj[1] + FefundConstants.BEGIN_CONTEXT_END
							+ FefundConstants.MSG_MIDDLE_CONTEXT + DateUtil.getSpecifiedDayBefore(-n) + "归还" + obj[4]
							+ FefundConstants.PAY_MENT_CONTEXT1;
				}
				O2OMessage message = new O2OMessage();
				message.setContent(content);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
				} else {
					message.setReceiveTelphone("13425116953");// obj[0].toString()
				}
				message.setReceiveName(obj[1].toString());
				message.setSendName(FefundConstants.SENDNAME);
				message.setCreateTime(new Date());
				message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				message.setMessageType(O2OMessage.MESSAGE_TYPE_FX + n);
				message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				message.setRelevanceId(obj[2].toString());
				message.setLoanapplyno(obj[3].toString());
				try {
					// 判断本地表是否有这条数据
					boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_FX + n, obj[2].toString());
					if (!flag) {
						o2OMessageDao.saveEntity(message);
						total++;
					}
				} catch (DataIntegrityViolationException e) {
					logger.error("主键重复异常:[{}]", e);
				}
			}
			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
		logger.info("查询国安村镇银行还息日前" + n + "天结束,插入短信条数：[{}]", total);
	}

	// 非国安村镇银行还息日前n天发送(每天执行一次)
	public void notGACZFundBeforeDay(int n) {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		int index = 0;// 第几页
		int total = 0;
		logger.info("查询非国安村镇银行还息日前" + n + "两天开始,所属环境是：[{}]", runtimeSetting.getEnv());
		String sql = "select lu.user_phone,lu.user_surname,ops.payments_id,l.bill_code,ops.pay_total,(select f.item_name from pub_dditem f where f.DD_NO=10340 and f.item_code= d.loan_bank ) as loan_bank_name  from "
				+ " ( SELECT nn.* from (select max(n.periods) as maxlength,n.bill_code  from o2o_payments_plan n where n.is_del='N' group by n.bill_code ) t,o2o_payments_plan nn where t.maxlength!=nn.periods and t.bill_code=nn.bill_code  and nn.is_del='N' ) "
				+ " ops "
				+ " LEFT JOIN o2o_loanapply l on l.bill_code = ops.bill_code  LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id "
				+ "	and l.loanapply_no=lu.loanapply_no  and lu.spouse_id is null and lu.sponsor_type is null "
				+ "	LEFT JOIN o2o_bank_loan_data d ON l.bill_code=d.bill_code AND d.is_del='N' "
				+ "	where  residual_principal != 0   and payments_date = adddate(curdate(),'" + n
				+ "  days') AND ops.is_del='N' " + "	and d.loan_bank not in( 'GACZ','EA') ";
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index,
					sql);
			PageResult<Object[]> pageResult = o2OMessageDao.findDataWithPage(sqlPageQuery);
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);
				String content = FefundConstants.BEGIN_CONTEXT + obj[1] + FefundConstants.BEGIN_CONTEXT_END
						+ FefundConstants.COMMON_CONTEXT + obj[5] + FefundConstants.COMMON_CONTEXT1
						+ DateUtil.getSpecifiedDayBefore(-n) + "归还" + obj[4] + FefundConstants.COMMON_CONTEXT2;

				O2OMessage message = new O2OMessage();
				message.setContent(content);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					message.setReceiveTelphone(obj[0].toString());// obj[0].toString()
				} else {
					message.setReceiveTelphone("13425116953");// obj[0].toString()
				}
				message.setReceiveName(obj[1].toString());
				message.setSendName(FefundConstants.SENDNAME);
				message.setCreateTime(new Date());
				message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				message.setMessageType(O2OMessage.MESSAGE_TYPE_FX + n);
				message.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				message.setRelevanceId(obj[2].toString());
				message.setLoanapplyno(obj[3].toString());
				try {
					// 判断本地表是否有这条数据
					boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_FX + n, obj[2].toString());
					if (!flag) {
						o2OMessageDao.saveEntity(message);
						total++;
					}
				} catch (DataIntegrityViolationException e) {
					logger.error("主键重复异常:[{}]", e);
				}
			}
			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
		logger.info("查询非国安村镇银行还息日前" + n + "天结束,插入短信条数：[{}]", total);
	}

	// 贷款到期前n天发送(国安村镇银行，每天执行一次)
	public void findFundBeforeEndByGACZ(int n, boolean isSendOperator) {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		int index = 0;// 第几页
		int total = 0;// 第几条数据
		logger.info("[国安村镇银行]贷款到期前" + n + "天发送短信数据插入开始,所属环境：[{}]", runtimeSetting.getEnv());
		String sql = " SELECT t.operator_no,t.operator_name,t.bill_code, lu.user_phone,lu.user_surname,"
				+ " y.payments_date,y.pay_total,t.loanapply_no FROM o2o_loanapply t LEFT JOIN "
				
				+ "( SELECT nn.* from (select max(n.periods) as maxlength,n.bill_code "
				+ " from o2o_payments_plan n where n.is_del='N' group by n.bill_code ) t,"
				+ " o2o_payments_plan nn where t.maxlength=nn.periods and t.bill_code=nn.bill_code  and nn.is_del='N' ) "				
				
				+ " y ON"				
				+ " t.bill_code = y.bill_code AND y.is_del = 'N' LEFT JOIN o2o_loan_user lu"
				+ " ON t.loan_id = lu.loan_id AND t.loanapply_no = lu.loanapply_no AND lu.spouse_id IS NULL"
				+ " LEFT JOIN o2o_bank_loan_data d ON t.bill_code=d.bill_code AND d.is_del='N' "
				+ " AND lu.sponsor_type IS NULL WHERE y.payments_date = adddate(curdate(), '" + n
				+ "  days') AND d.loan_bank='GACZ' ";
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index,
					sql);
			PageResult<Object[]> pageResult = o2OMessageDao.findDataWithPageByService(sqlPageQuery);
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);
				// 客户短信
				String contentCrmotolaner = FefundConstants.BEGIN_CONTEXT + obj[4] + FefundConstants.BEGIN_CONTEXT_END
						+ FefundConstants.MSG_MIDDLE_CONTEXT + DateUtil.getSpecifiedDayBefore(-n) + "归还本息" + obj[6]
						+ FefundConstants.EXPIRE_FIFTEEN_CONTEXT;
				O2OMessage messageCrmotolaner = new O2OMessage();
				messageCrmotolaner.setContent(contentCrmotolaner);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					messageCrmotolaner.setReceiveTelphone(obj[3].toString());
				} else {
					messageCrmotolaner.setReceiveTelphone("13425116953");
				}
				messageCrmotolaner.setReceiveName(obj[4].toString());
				messageCrmotolaner.setSendName(FefundConstants.SENDNAME);
				messageCrmotolaner.setCreateTime(new Date());
				messageCrmotolaner.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				messageCrmotolaner.setMessageType(O2OMessage.MESSAGE_TYPE_GACZ_DK + n);
				messageCrmotolaner.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				messageCrmotolaner.setRelevanceId(DigestUtils.md5With16(UuidUtil.generateFullUuid()));
				messageCrmotolaner.setLoanapplyno(obj[2].toString());
				try {
					// 判断本地表是否有这条数据
					boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_GACZ_DK + n,
							messageCrmotolaner.getRelevanceId());
					if (!flag) {
						o2OMessageDao.saveEntity(messageCrmotolaner);
						total++;
					}
				} catch (DataIntegrityViolationException e) {
					logger.info("[国安村镇银行]贷款到期前" + n + "天发送发送短信数据插入异常：[{}]", e.getMessage());
				}

				if (isSendOperator) {
					String hrSql = "SELECT * FROM hr_employee t where t.EMPLOYEESTATUS !='DMS' and t.EMPLOYEENO=?";
					com.eascs.web.o2o.scheduler.entity.HrEmployee employee = o2OMessageDao.findEntityDev(hrSql,
							com.eascs.web.o2o.scheduler.entity.HrEmployee.class, obj[0]);
					if (employee != null) {
						// 信贷经理短信
						String contentOperator = FefundConstants.START_CONTEXT2 + "，你的客户" + obj[4] + "先生/女士应于"
								+ DateUtil.getSpecifiedDayBefore(-n) + "归还本息" + obj[6]
								+ FefundConstants.BEFOREEND15_CONTEXT_OPERATOR;
						O2OMessage messageOperator = new O2OMessage();
						messageOperator.setContent(contentOperator);
						if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
							messageOperator.setReceiveTelphone(employee.getMobile());
						} else {
							messageOperator.setReceiveTelphone("13425116953");
						}
						messageOperator.setReceiveName(obj[1].toString());
						messageOperator.setSendName(FefundConstants.SENDNAME);
						messageOperator.setCreateTime(new Date());
						messageOperator.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
						messageOperator.setMessageType(O2OMessage.MESSAGE_TYPE_GACZ_DK + n);
						messageOperator.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
						messageOperator.setRelevanceId(DigestUtils.md5With16(UuidUtil.generateFullUuid()));
						messageOperator.setLoanapplyno(obj[2].toString());
						try {
							// 判断本地表是否有这条数据
							boolean flag = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_GACZ_DK + n,
									messageOperator.getRelevanceId());
							if (!flag) {
								o2OMessageDao.saveEntity(messageOperator);
							}
						} catch (DataIntegrityViolationException e) {
							logger.info("[国安村镇银行]贷款到期前" + n + "天发送发送短信数据插入异常：[{}]", e.getMessage());
						}

					}
				}
			}
			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
		logger.info("[国安村镇银行]贷款到期前" + n + "天发送短信数据插入结束,总插入记录数：[{}]", total);
	}

	// 贷款到期前n天发送(非国安村镇银行，每天执行一次)
	public void findFundBeforeEndByNotGACZ(int n, boolean isSendOperator) {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		int index = 0;// 第几页
		int total = 0;// 第几条数据
		logger.info("[非国安村镇银行]贷款到期前" + n + "天发送短信数据插入开始,所属环境：[{}]", runtimeSetting.getEnv());
		String sql = " SELECT t.operator_no,t.operator_name,t.bill_code, lu.user_phone,lu.user_surname,"
				+ " y.payments_date,y.pay_total,(select f.item_name from pub_dditem f where f.DD_NO=10340 and f.item_code= d.loan_bank ) as loan_bank_name FROM o2o_loanapply t LEFT JOIN "
				+ "( SELECT nn.* from (select max(n.periods) as maxlength,n.bill_code "
				+ " from o2o_payments_plan n where n.is_del='N' group by n.bill_code ) t,"
				+ " o2o_payments_plan nn where t.maxlength=nn.periods and t.bill_code=nn.bill_code  and nn.is_del='N' ) "				
				
				+ " y ON"
				+ " t.bill_code = y.bill_code AND y.is_del = 'N' LEFT JOIN o2o_loan_user lu"
				+ " ON t.loan_id = lu.loan_id AND t.loanapply_no = lu.loanapply_no AND lu.spouse_id IS NULL"
				+ " LEFT JOIN o2o_bank_loan_data d ON t.bill_code=d.bill_code AND d.is_del='N' "
				+ " AND lu.sponsor_type IS NULL WHERE y.payments_date= adddate(curdate(), '" + n
				+ "  days') AND  d.loan_bank not in('GACZ','EA') ";
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index,
					sql);
			PageResult<Object[]> pageResult = o2OMessageDao.findDataWithPageByService(sqlPageQuery);
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);

				// 客户短信内容
				String contentByCrmotolaner = FefundConstants.BEGIN_CONTEXT + obj[4] + FefundConstants.BEGIN_CONTEXT_END
						+ FefundConstants.COMMON_CONTEXT + obj[7] + FefundConstants.COMMON_CONTEXT1
						+ DateUtil.getSpecifiedDayBefore(-n) + "归还本息" + obj[6] + FefundConstants.EXPIRE_FIFTEEN_CONTEXT;
				// 客户短信
				O2OMessage messageByCrmotolaner = new O2OMessage();
				messageByCrmotolaner.setContent(contentByCrmotolaner);
				if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
					messageByCrmotolaner.setReceiveTelphone(obj[3].toString());
				} else {
					messageByCrmotolaner.setReceiveTelphone("13425116953");
				}
				messageByCrmotolaner.setReceiveName(obj[4].toString());
				messageByCrmotolaner.setSendName(FefundConstants.SENDNAME);
				messageByCrmotolaner.setCreateTime(new Date());
				messageByCrmotolaner.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				messageByCrmotolaner.setMessageType(O2OMessage.MESSAGE_TYPE_NOT_GACZ_DK + n);
				messageByCrmotolaner.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
				messageByCrmotolaner.setRelevanceId(DigestUtils.md5With16(UuidUtil.generateFullUuid()));
				messageByCrmotolaner.setLoanapplyno(obj[2].toString());
				try {
					// 判断本地表是否有这条数据
					boolean flag2 = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_NOT_GACZ_DK + n,
							messageByCrmotolaner.getRelevanceId());
					if (!flag2) {
						o2OMessageDao.saveEntity(messageByCrmotolaner);
						total++;
					}
				} catch (DataIntegrityViolationException e) {
					logger.info("[非国安村镇银行]贷款到期前" + n + "天发送发送短信数据插入异常：[{}]", e.getMessage());
				}
				if (isSendOperator) {
					// 信贷经理短信内容
					String contentByOperator = FefundConstants.START_CONTEXT2 + "，您的客户" + obj[4] + "应于"
							+ DateUtil.getSpecifiedDayBefore(-n) + "归还本息" + obj[6]
							+ FefundConstants.NOTBEFOREEND15_CONTEXT_OPERATOR;
					// 信贷经理短信
					String hrSql = "SELECT * FROM hr_employee t where t.EMPLOYEESTATUS !='DMS' and t.EMPLOYEENO=?";
					HrEmployee employee = o2OMessageDao.findEntityDev(hrSql, HrEmployee.class, obj[0]);
					if (employee != null) {
						O2OMessage messageByOperator = new O2OMessage();
						messageByOperator.setContent(contentByOperator);
						if (runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)) {
							messageByOperator.setReceiveTelphone(employee.getMobile());// obj[0].toString()
						} else {
							messageByOperator.setReceiveTelphone("13425116953");// obj[0].toString()
						}
						messageByOperator.setReceiveName(obj[1].toString());
						messageByOperator.setSendName(FefundConstants.SENDNAME);
						messageByOperator.setCreateTime(new Date());
						messageByOperator.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
						messageByOperator.setMessageType(O2OMessage.MESSAGE_TYPE_NOT_GACZ_DK + n);
						messageByOperator.setPlatformType(O2OMessage.PLATFORM_TYPE_NEW);
						messageByOperator.setRelevanceId(DigestUtils.md5With16(UuidUtil.generateFullUuid()));
						messageByOperator.setLoanapplyno(obj[2].toString());
						try {
							boolean flag1 = o2OMessageDao.isExist(O2OMessage.MESSAGE_TYPE_NOT_GACZ_DK + n,
									messageByOperator.getRelevanceId());
							if (!flag1) {
								o2OMessageDao.saveEntity(messageByOperator);
							}
						} catch (Exception e) {
							logger.info("插入信贷经理短信异常:[{}]", e.getMessage());
						}
					}

				}
			}
			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
		logger.info("[非国安村镇银行]贷款到期前" + n + "天发送短信数据插入结束,总计插入条数:[{}]", total);
	}

	public boolean isBillCode(String billCode) {
		String[] strs = { "DB00-BK-1612-00013", "H700-BK-1611-00003", "G700-BK-1612-00004", "H900-BK-1612-00002",
				"H100-BK-1612-00013", "R400-BK-1612-00013", "GN00-BK-1612-00001", "L500-BK-1612-00001",
				"U200-BK-1612-00001", "U200-BK-1611-00001", "HU00-BK-1612-00003", " DU00-BK-1612-00003",
				" 1151-BK-1612-00001", "X900-BK-1611-00007", " AH00-BK-1612-00002", " U600-BK-1612-00001",
				"EV00-BK-1612-00002", "U100-BK-1612-00001", "GH00-BK-1612-00009", " EV00-BK-1612-00003",
				"BY00-BK-1612-00003", "BE00-BK-1612-00003", "G700-BK-1612-00008", "BY00-BK-1612-00004",
				"N300-BK-1612-00005", " C700-BK-1612-00002", "DU00-BK-1612-00004", "P600-BK-1612-00010",
				"SK0027-BK-1612-00005", "Y100-BK-1612-00005", "CX00-BK-1612-00006", "H100-BK-1612-00009",
				"H300-BK-1612-00001", "U300-BK-1611-00005", "G700-BK-1612-00005", "N300-BK-1611-00014",
				"Y100-BK-1612-00004", "L400-BK-1612-00015", "D200-BK-1611-00002", "1138-BK-1612-00008",
				"H100-BK-1612-00005", "H100-BK-1611-00030", "U300-BK-1611-00008", "J200-BP-1612-00002",
				"J200-BK-1612-00001", "N900-BK-1612-00003", "G700-BK-1612-00007", "SK002-BK-1610-00002 ",
				"CP00-BK-1612-00011", "L400-BK-1612-00008", " GJ00-BK-1612-00006", "DE00-BK-1612-00002",
				"DE00-BK-1612-00001", "Y200-BK-1611-00002", "L201-BK-1612-00004", "G100-BK-1611-00001",
				"S300-BK-1612-00005", "EW00-BK-1612-00005", "EW00-BK-1612-00004", "CP00-BK-1611-00004",
				"J200-BK-1611-00003", "H200-BK-1611-00005", "EW00-BK-1612-00003", "N300-BK-1612-00004",
				"GC00-BK-1611-00003", "T500-BK-1611-00003", "HA00-BK-1612-00001", "S900-BK-1611-00007",
				"R400-BK-1611-00025", "G100-BK-1612-00002", "H200-BK-1612-00001", "L201-BK-1612-00001",
				"M700-BK-1610-00011", "M700-BK-1611-00005", "R400-BK-1612-00004", "R400-BK-1609-00014",
				"AU00-BK-1612-00002", "R300-BK-1612-00005", "CT00-BK-1612-00001", "GH00-BK-1612-00008",
				"H900-BK-1612-00001", "R400-BK-1612-00007", "H100-BK-1611-00020", "BZ00-BK-1611-00002",
				"N900-BK-1612-00002", "LH00-BK-1611-00001", "L400-BK-1612-00013", "H700-BK-1612-00005",
				"L900-BK-1612-00003", "SK002-BK-1611-00003", "BA00-BK-1612-00007", "L900-BK-1612-00010",
				"N900-BK-1612-00007", "L400-BK-1612-00012", "LB00-BK-1612-00001", "S300-BK-1612-00001",
				"T500-BK-1611-00002", "G700-BK-1612-00003", "K700-BK-1612-00001", "G100-BK-1611-00008",
				"AV00-BK-1612-00003", "AS00-BK-1612-00002", "HS00-BK-1612-00004", "P500-BK-1612-00003",
				"M700-BK-1612-00002", "J200-BK-1611-00010", "P500-BK-1612-00002", "GH00-BK-1612-00005",
				"T500-BK-1612-00001", "H900-BK-1612-00004", "W800-BK-1612-00001", "G100-BK-1611-00006",
				"H100-BK-1611-00010", "H700-BK-1611-00004", "H700-BK-1612-00004", "W300-BK-1612-00001",
				"Y100-BK-1612-00002", "AV00-BK-1612-00001", "AU00-BK-1612-00001", "GJ00-BK-1612-00008",
				"DT00-BK-1611-00003", "Y100-BK-1611-00010", "G100-BK-1612-00001", "Y100-BK-1611-00009",
				"V600-BK-1612-00005", "J200-BP-1612-00001", "GH00-BK-1612-00002", "R100-BK-1612-00003",
				"EN00-BK-1612-00001", "HS00-BK-1611-00005", "V200-BK-1612-00002", "1132-BK-1612-00001",
				"L201-BK-1611-00006", "L400-BK-1612-00007", "G500-BK-1612-00001", "JQ00-BK-1611-00002",
				"LA00-BK-1612-00001", "J800-BK-1612-00001", "G500-BK-1611-00002", "P500-BK-1612-00001",
				"T100-BK-1612-00002", "T600-BK-1611-00004", "V100-BK-1612-00001", "U300-BK-1612-00001",
				"EX00-BK-1611-00001", "L201-BK-1611-00007", "V600-BK-1612-00004", "V600-BK-1611-00011",
				"H100-BK-1611-00021", "1138-BK-1612-00004", "1138-BK-1612-00003", "ET00-BK-1612-00004",
				"H100-BK-1611-00018", "L200-BK-1611-00002", "L400-BK-1612-00020", "S900-BK-1611-00004",
				"L400-BK-1612-00005", "EH00-BK-1611-00004", "G700-BK-1612-00001", "CX00-BK-1611-00015",
				"EG00-BK-1612-00003", "C700-BK-1611-00004", "W800-BK-1612-00003", "AD00-BK-1612-00002",
				"L900-BK-1612-00004", "L400-BK-1612-00014", "GJ00-BK-1612-00009", "H100-BK-1611-00026",
				"H100-BK-1611-00004", "H100-BK-1611-00024", "H100-BK-1611-00007", "EW00-BK-1611-00002",
				"GJ00-BP-1612-00002", "BA00-BK-1612-00006", "T900-BK-1611-00005", "Y100-BK-1612-00001",
				"BA00-BK-1611-00006", "ET00-BK-1612-00001", "L201-BK-1611-00010", "DB00-BK-1612-00003",
				"T900-BK-1611-00008", "D500-BK-1612-00002", "W800-BK-1611-00004", "R400-BK-1611-00003",
				"Y200-BK-1612-00001", "1132-BK-1611-00003", "GJ00-BK-1612-00002", "L900-BK-1612-00009",
				"AU00-BK-1612-00003", "HU00-BK-1612-00001", "GH00-BK-1612-00004", "CA00-BK-1612-00001",
				"BY00-BK-1611-00009", "V700-BK-1612-00001", "CX00-BK-1612-00002", "BY00-BK-1612-00006",
				"BY00-BK-1612-00001", "L400-BK-1612-00017", "G700-BK-1612-00002", "AA00-BK-1612-00003",
				"R400-BK-1612-00009", "L201-BK-1611-00009", "N300-BK-1611-00008", "CP00-BK-1611-00006",
				"L400-BK-1611-00022", "S300-BK-1612-00003", "AD00-BK-1611-00006", "N300-BK-1611-00013",
				"AS00-BK-1612-00001", "HE00-BK-1612-00001", "D400-BK-1611-00004", "N300-BK-1611-00010",
				"L400-BK-1612-00003", "CX00-BK-1610-00017", "R100-BK-1612-00002", "N300-BK-1612-00003",
				"AU00-BK-1612-00004", "AS00-BK-1611-00004", "L400-BK-1612-00011", "GJ00-BP-1612-00001",
				"GJ00-BK-1612-00005", "W200-BK-1611-00003", "EN00-BK-1612-00002", "R300-BK-1612-00001",
				"T900-BK-1612-00001", "J200-BK-1611-00005", "R300-BK-1612-00003", "H100-BK-1611-00003",
				"P600-BK-1612-00006", "V100-BK-1611-00001", "P600-BK-1612-00005", "P600-BK-1612-00009",
				"N300-BK-1612-00002", "T900-BK-1612-00002", "HS00-BK-1611-00006", "HS00-BK-1612-00003",
				"V100-BK-1611-00002", "JU00-BK-1611-00001", "AA00-BK-1610-00004", "EW00-BK-1612-00002",
				"P600-BK-1612-00003", "P600-BK-1612-00007", "SK0027-BK-1612-00001", "SK0027-BK-1612-00004",
				"EH00-BK-1612-00003", "DB00-BK-1611-00009", "T100-BK-1612-00001", "T600-BK-1612-00001",
				"T900-BK-1612-00003", "EW00-BK-1611-00001", "AA00-BK-1612-00001", "P700-BK-1612-00006",
				"L900-BK-1612-00001", "AU00-BK-1611-00008", "P600-BK-1611-00006", "AV00-BK-1612-00005",
				"J200-BK-1611-00007", "J700-BK-1612-00001", "J700-BK-1612-00003", "AS00-BK-1611-00006",
				"HS00-BK-1612-00001", "HS00-BK-1611-00004", "CF00-BK-1612-00001", "H100-BK-1611-00027",
				"EV00-BK-1612-00001", "SK0027-BK-1612-00006", "GJ00-BK-1612-00004", "L400-BK-1612-00016",
				"L400-BK-1610-00001", "AV00-BK-1612-00002", "BY00-BK-1612-00005", "1138-BK-1612-00002",
				"L400-BK-1612-00019", "P700-BK-1612-00005", };
		List<String> arraylist = Arrays.asList(strs);
		if (arraylist.contains(billCode.trim())) {
			return true;
		}
		return false;
	}
}
